﻿
namespace md.imi.membranes.objects
{
    using System.Collections.Generic;
    using md.imi.membranes.objects.membranes;
    using md.imi.membranes.objects.rules;
    using md.imi.membranes.objects.strings;

    public class Solution
    {
        /// <summary>
        ///     The string which is searched in mebrane for which rule is applied
        /// </summary>
        public StringObject ProcessedString { get; set; }

        /// <summary>
        /// the index of a substring formed from alphabet objects
        /// </summary>
        public int ProcessedSubStringIndex { get; set; }

        /// <summary>
        /// the index of a string from a list of strings which are located in membrane
        /// /// </summary>
        public int ProcessedStringIndex { get; set; }

        /// <summary>
        ///
        /// </summary>
        public Rule AppliedRule { get; set; }

        /// <summary>
        ///     Gets or sets the membrane on which this solution is applied.
        /// </summary>
        public Membrane Membrane { get; set; }

        public override string ToString()
        {
            string ruleLabel = "";

            if (AppliedRule is ReplicationRule)
            {
                ruleLabel = (AppliedRule as ReplicationRule).Label;
            }

            return string.Format("Membrane: {0}, Rule: {1}, String: {2}, Position: {3}",
                Membrane.Label, ruleLabel, ProcessedString, ProcessedSubStringIndex);
        }
        
        public static string GenerateRooSolutionTitle(List<Solution> solutionsItem)
        {
            if (solutionsItem == null || solutionsItem.Count == 0)
            {
                return "<NONE>";
            }

            var title = "";
            foreach (var solution in solutionsItem)
            {
                if (title.Length > 0)
                {
                    title += ", ";
                }

                title += string.Format("{0}-{1}", solution.Membrane.Label, solution.AppliedRule.Label);
            }

            return title;
        }

    }
}